import { def } from "./util"
import { arrayMethods } from "./array"
import defineReactive from "./defineReactive"
import observe from "./observe"
import Dep from "./Dep"
// Observer类的目的是：将一个正常的object转换为每个层级的属性都是响应式的
export default class Observer {
  constructor(value) {
    this.dep = new Dep()
    def(value, "__ob__", this, false)
    // console.log("类 Observer实列", value)

    if (Array.isArray(value)) {
      // 如果是数组 数组的原型指向arrayMethods
      Object.setPrototypeOf(value, arrayMethods)
      this.observeArray(value)
    } else {
      this.walk(value)
    }
  }
  walk(value) {
    for (const key in value) {
      defineReactive(value, key)
    }
  }
  observeArray(arr) {
    for (let index = 0, l = arr.length; index < l; index++) {
      observe(arr[index])
    }
  }
  // 数组遍历
}
